function ajax(obj) {
	return $.ajax(obj);
}

function hide(element) {
	$(element).removeClass("show").addClass("hide");
}

function show(element) {
	$(element).removeClass("hide").addClass("show");
}

function getCountry(elem, elstate, idcountry, extraurl) {
	idcountry = idcountry ? idcountry : '#idcountry';
	
	ajax({
		  url: baseURL + "ajax/get_country" + (extraurl ? extraurl : ''),
		  cache: false,
		  type: "POST",
		  async: false,
		  data: 'idcountry=' + idcountry,
		  dataType: 'html',
		  success: function(data) {
			  $(elem).html(data);
			  if (elstate)
				  getState(elstate);
		  }
		});
}

function getState(elem, idcountry, extraurl) {
	elem = elem ? elem : '#ajaxState';
	idcountry = idcountry ? idcountry : '#idcountry';

	if ($(idcountry).val()) {
		ajax({
			  url: baseURL + "ajax/get_state" + (extraurl ? extraurl : ''),
			  cache: false,
			  type: "POST",
			  async: false,
			  data: 'idcountry=' + $(idcountry).val(),
			  dataType: 'html',
			  success: function(data) {
				  $(elem).html(data);
			  }
			});
	} else {
		$(elem).html('<div>' + ajax_lang[0] + '</div>');
	}
}

function getZipCodeAddress(zipCode) {
	zipCode = $('#zipcode').val();
	
	if (zipCode.length == 9) {
		ajax({
			  url: baseURL + "ajax/get_zipcode_address",
			  cache: false,
			  type: "POST",
			  async: false,
			  data: 'zipcode=' + zipCode,
			  dataType: 'script'
			});
	}
	
	/*
	var geocoder = new google.maps.Geocoder();
	
	zipCode = zipCode ? zipCode : $('#zipcode').val();
	
	var neighFound = false;
	var cityFound = false;

	geocoder.geocode({'address': $("#idcountry option:selected").text() + ' ' + zipCode}, function (result, status) {
        console.log(result);
		for (var component in result[0]['address_components']) {
            for (var i in result[0]['address_components'][component]['types']) {
               switch (result[0]['address_components'][component]['types'][i]) {
               		case 'sublocality':
               			try {
               				$("#neighborhood").val(result[0]['address_components'][component].long_name);
               				neighFound = true;
               			} catch(e) {};
               			break;
               		case 'locality':
               			try {
               				$("#city").val(result[0]['address_components'][component].long_name);
               				cityFound = true;
               			} catch(e) {};
               			break;
               		case 'administrative_area_level_1':
               			try {
               				var longName = result[0]['address_components'][component].long_name;
               				$("#idstate").val($("#idstate option:contains('"+longName+"')").val());
               			} catch(e) {};
               			break;
               		case 'country':
               			try {
               				var longName = result[0]['address_components'][component].long_name;
               				$("#idcountry").val($("#idcountry option:contains('"+longName+"')").val());
               			} catch(e) {};
               			break;
               }
            }
        }
    });
	
	if (!neighFound) {
		$("#neighborhood").val('');
	}
	
	if (!cityFound) {
		$("#city").val('');
	}
	*/
}

function checkSubscriptionStatus(idsubscription, idstatus) {
	if (idstatus) {
		ajax({
			  url: baseURL + "ajax/check_subscription_status",
			  cache: false,
			  type: "POST",
			  async: false,
			  data: 'idsubscription=' + idsubscription + '&idstatus=' + idstatus,
			  dataType: 'html',
			  success: function(data) {
				  document.location.reload();
			  }
			});
	}
}

function loadFacebox() {
	$('a[rel*=facebox]').facebox({
      loadingImage : baseURL + 'images/loading.gif',
      closeImage   : baseURL + 'images/closelabel.png'
    });
}

function showBox(content) {
	jQuery.facebox(content);
}

function closeBox() {
	$(document).trigger('close.facebox');
}

jQuery(document).ready(function($) {
	loadFacebox();
})